package com.yhally.seata.order.controller;

import com.yhally.seata.common.domain.CommonResult;
import com.yhally.seata.order.domain.Order;
import com.yhally.seata.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangyu
 * @version 1.0
 * @date 2022/5/6 23:00
 */
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
public class OrderController {

    private final OrderService orderService;

    /**
     * <p>描述: AT模式，请求方式 /order/create?userId=1&productId=1&count=10&money=100
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 21:44
     *
     * @param order
     * @return CommonResult
     */
    @GetMapping("/create")
    public CommonResult create(Order order) {
        orderService.create(order);
        return new CommonResult(200, "订单创建完成");
    }

    /**
     * <p>描述: TCC模式 请求方式同上
     * <p>开发者: wangyu
     * <p>时间: 2022/5/8 21:46
     *
     * @param order
     * @return CommonResult
     */
    @GetMapping("/createByTcc")
    public CommonResult createByTcc(Order order) {
        orderService.createByTcc(order);
        return new CommonResult(200, "订单创建完成");
    }
}
